import rtconfig
from building import *

cwd = GetCurrentDir()

# The set of source files associated with this SConscript file.
src = Split("""
Src/stm32f1xx_hal_msp.c
Src/system_stm32f1xx.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_crc.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_rcc.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cec.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_sram.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c
""")
    
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_usart.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_spi.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd_ex.c'] 
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_hcd.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_can.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_eth.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc_ex.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_wwdg.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_sdmmc.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_sd.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2s.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_nor.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_nand.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c']
src += ['Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c']

src += Glob('Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_gpio.c')


# add startup file
if rtconfig.CROSS_TOOL == 'gcc':
    src += ['gcc/startup_stm32f103xe.s']
elif rtconfig.CROSS_TOOL == 'keil':
    src += ['MDK-ARM/startup_stm32f103xe.s']
elif rtconfig.CROSS_TOOL == 'iar':
    src += ['EWARM/startup_stm32f103xe.s']

path = 	\
[
	cwd + '/Drivers/CMSIS/Device/ST/STM32F1xx/Include', 
    cwd + '/Drivers/STM32F1xx_HAL_Driver/Inc',
    cwd + '/Drivers/CMSIS/Include',
    cwd + '/Inc'
]
    
CPPDEFINES = ['STM32F103xE','USE_HAL_DRIVER']
group = DefineGroup('CubeMx', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)

Return('group')    